package com.itheima.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * AOP 通知类型
 */
@Slf4j
@Component
//@Aspect //切面类
public class AspectDemo1 {

    @Pointcut("execution(* com.itheima.service.*.*(..))")
    public void pt1() {    }

    //前置通知
    @Before("pt1()")
    public void before() {log.info("前置通知...");}

    //最终通知
    @After("pt1()")
    public void after() {log.info("最终通知...");}

    //环绕通知
    @Around("execution(* com.itheima.service.*.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        log.info("类似于前置通知...");
        Object result = pjp.proceed();
        log.info("类似于后置通知...");
        return result;
    }
    //异常通知
    @AfterThrowing("execution(* com.itheima.service.*.*(..))")
    public void afterThrowing() {log.info("异常通知...");}

    //后置通知
    @AfterReturning("execution(* com.itheima.service.*.*(..))")
    public void afterReturning() {log.info("后置通知...");}


}
